﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FineAdmin.IService;
using FineAdmin.Model;
using FineAdmin.IRepository;
using FineAdmin.Common;

namespace FineAdmin.Service
{
    public class SystemParameterService : BaseService<SystemParameterModel>, ISystemParameterService
    {
        public ISystemParameterRepository SystemParameterRepository { get; set; }
        public IEnumerable<SystemParameterModel> GetSystemParameterList()
        {
            return SystemParameterRepository.GetSystemParameterList();
        }


        public dynamic GetListByFilter(SystemParameterModel filter, PageInfo pageInfo)
        {
            string _where = " where 1=1";
            return GetListByFilter(filter, pageInfo, _where);
        }

        public int UpDateVale(string code, string value)
        {
            var sp = SystemParameterRepository.GetByWhere("where Code=@Code", new { Code = code }).FirstOrDefault();
            if (sp == null)
            {
                return -1;
            }
            else
            {
                sp.SPValue = value;
                return SystemParameterRepository.UpdateById(sp);
            }
        }

        public SystemParameterModel GetByCode(string code)
        {
           
            var ret = SystemParameterRepository.GetByCode(code);
            if (ret == null) {
                ret = new SystemParameterModel();
                ret.SPValue = string.Empty; 
            }
            return ret;
        }
    }

}